package com.quickcode.threadlocal.filter;

import com.quickcode.threadlocal.holder.ThreadHolder;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import java.io.IOException;

/**
 * Created by 张波 on 2019/10/23.
 */
@Slf4j
public class ThreadFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("thread id:{}" ,Thread.currentThread().getId());
        ThreadHolder.set(Thread.currentThread().getId());
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
